<!-- 评分等级-黑名单-->
<template>
  <div>
    <Add ref="add" @ok="search"></Add>
    <Configuration ref="configuration" @ok="search"></Configuration>
    <ZgNewPage
      ref="page"
      :title="pageTitle"
      :showInlineBtn="false"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :dataBtns="dataBtns"
      :extraBtns="extraBtns"
      :headers="headers"
      :conditions="conditions"
      :adminWidth="100"
      @search="onSearch"
      @filter="onFilter"
      @header="mergeHeader"
      @admin="toAdmin"
      @extra="toExtra"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h,i) in headers"
          :key="`column${i}`"
          :width="h.width===0 ? 'auto' : h.width"
          align="center"
          :title="h.label">
          <template slot-scope="record">
            <template>{{ record[h.code] }}</template>
          </template>
        </a-table-column>
      </template>
      <template slot="thMode" slot-scope="scope">
        <a-row :gutter="10">
          <a-col :span="4" v-for="t in scope.list" :key="`thMode_${t.id}`">
            <a-card class="mb10">
              <div class="wfull h100 scroll">
                {{ t }}
              </div>
            </a-card>
          </a-col>
        </a-row>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
import Add from './Add'
import Configuration from './Configuration'
const statusList = [
    { value: '1', label: '审核通过' },
    { value: '2', label: '待审核' },
    { value: '3', label: '驳回' }
]
export default {
    components: {
      Add, Configuration
  },
  data () {
    return {
      pageTitle: '等级管理',
      uniqueName: 'test',
      reviewStatus: {
        '1': '暂存',
        '2': '已提交',
        '3': '已授信',
        '4': '已驳回',
        '5': '已作废',
        '6': '已撤销'
      },
      pageOpt: {
        showConditionBtn: true,
        showHeaderConfig: true,
        showAttachBtn: true,
        showDataCheck: true,
        showPageTitle: false
      },
      conditions: [
        { code: 'name', compType: '单行文本', label: '机构名称', defaultVal: '' },
        { code: 'birth', compType: '日期区间', label: '生效失效', defaultVal: ['', ''] },
        { code: 'status', compType: '下拉选择', label: '状态', defaultVal: '', extra: { 下拉选项: statusList } }
      ],
      headers: [
        { code: 'A', label: '机构名称', isShow: true, sort: 0 },
        { code: 'B', label: '说明', isShow: true, sort: 0 },
        { code: 'C', label: '开始时间', isShow: true, sort: 0 },
        { code: 'D', label: '结束时间', isShow: true, sort: 0 },
        { code: 'E', label: '状态', isShow: true, sort: 0 }
      ],
      dataBtns: [
        { key: 1, name: '失效', type: 'link', isShow: (row) => row.E === '生效中' },
        { key: 2, name: '生效', type: 'link', isShow: (row) => row.E === '已失效' }
      ],
      extraBtns: [
        { key: 1, name: '新增', icon: 'plus-circle', type: 'primary' },
        { key: 2, name: '配置', icon: '', type: 'primary' }
      ]
    }
  },
  methods: {
    search () {
      this.$refs.page.search()
    },
    onSearch (param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        { key: '1', id: '1', A: '1111', B: 'sfsdfsfffsf', C: '2015-06-01 12:30', D: '2015-06-01 12:30', E: '生效中' },
        { key: '2', id: '2', A: '2222', B: 'sfsfsfsdfsfsdfsf', C: '2015-06-01 12:30', D: '2015-06-01 12:30', E: '已失效' }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    onFilter (f, param) {
    },
    toAdmin (param) {
      if (param.key === 1) {
        alert('失效')
      } else if (param.key === 2) {
        alert('生效')
      }
    },
    toExtra (opt) {
      if (opt.key === 1) {
        this.$refs.add.open()
      } else if (opt.key === 2) {
        this.$refs.configuration.open()
      }
    },
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders.filter(t => {
        return t.isShow
      }).sort((a, b) => {
        return a.sort - b.sort
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
